<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,height=device-height,inital-scale=1.0,maximum-scale=1.0,user-scalable=no;">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta name="format-detection" content="telephone=no" />
    <title>云拍</title>
    <link rel="stylesheet" href="css/style.css">
    <link rel="stylesheet" href="css/index.css">
    <script src="js/jquery-1.8.3.min.js"></script>
    <script src="js/public.js"></script>
</head>

<body>
    <div class="greet">
        <img src="image/ytop.png" alt="">
    </div>
    <!--兑换列表-->
    <div class="wrap">
        <div class="wrap-top">
            <span>限时拍卖</span>
            <a href="indent.html">我的兑换 &gt</a>
        </div>
    </div>
    <!--提示框-->
    <div class="item">
        <div class="hint">
            <div class="hint-pic">
                <img src="image/succ-tip.png" class="tip" alt="">
            </div>
            <p class="hint-erro"></p>
            <input type="button" class="hint-btn" value="我知道了">
        </div>
    </div>

</body>

<script>
    $(function () {
        var url = 'http://ysapi.jin315.com/',
            str = '',
            goodId = [];

        //列表请求 	
        $.ajax({
            type: "GET",
            url: url + "getGoodsList.ashx",
            dataType: "jsonp",
            jsonp: "jsonpCallback",
            jsonpCallback: "jsonpCallback",
            success: function (data) {
                if (data && data.code == 200) {
                    var data = data.data.goodsList;

                    for (var i = 0; i < data.length; i++) {
                        goodId.push(data[i].GoodID);
												data[i].title = '进行中';
												data[i].clas = 'wrap-cash';
                        //判断状态 
                        if (data[i].ProductStatus == 1) {
                            data[i].title = '进行中';
                            data[i].clas = 'wrap-cash';
                        } else if (data[i].ProductStatus == 0) {
                            data[i].title = '已结束';
                            data[i].clas = 'wrap-default';
                        }

                        str += '<div class="wrap-list">' +
                            '<div class="wrap-img">' +
                            '<img src=' + data[i].HeaderPic + ' alt=' + data[i].GoodTitle + '>' +
                            '</div>' +
                            '<div class="wrap-body">' +
                            '<h3 class="wrap-title">' + data[i].GoodTitle + '</h3>' +
                            '<p class="wrap-y">成交价（云钻数）</p>' +
                            '<p class="wrap-num">' + data[i].PriceYunZuan + '</p>' +
                            '<span class="wrap-state">' + data[i].title + '</span>' +
                            '<span class="wrap-total">参与人数 ' +
                            '<span class="total-num">' + data[i].RemainCount + '</span>' +
                            '</span>' +
                            '<button class=' + data[i].clas + '>我要兑换</button>' +
                            '</div>' +
                            '</div>';

                    }
                    $('.wrap').append(str);
                    var oBtun = document.getElementsByTagName('button');
                    var href = location.href;
                    var userid = href.split('userid='); //获取userid

                    for (var i = 0; i < oBtun.length; i++) {
                        oBtun[i].index = i;
                        oBtun[i].onclick = function () {

                            $.ajax({
                                type: "GET",
                                url: url + "validateGoodsOrder.ashx",
                                data: {
                                    goodsId: goodId[this.index],
                                    userID: userid
                                },
                                dataType: "jsonp",
                                jsonp: "jsonpCallback",
                                jsonpCallback: "jsonpCallback",
                                success: function (data) {
									
                                    if (data && data.code == 200) {
                                       tip('tip','image/succ-tip.png','恭喜您，已经兑换成功');
																				//兑换成功跳转商品详情页 
                                        window.location.href = '/goods.html&goodsid='+goodId[this.index];
                                    } else if (data.code == 221) {
																				tip('tip','image/err-tip.png',data.msg);
                                    } else if (data.code == 222) {
                                        tip('cry','image/cry.png',data.msg);
                                    } else if (data.code == 223) {
                                        tip('cry','image/cry.png',data.msg);
                                    } else if (data.code == 224) {
                                        tip('cry','image/cry.png',data.msg);
                                    } else if (data.code == 225) {
																				tip('cry','image/cry.png',data.msg);
                                    }else{
																			console.log(data.msg);
																		}
                                },
                                error: function () {
                                    console.log(data.msg);
                                }
                            })
                        }
                    }					

                }
            }
        });
		//兑换提示 
		function tip(attr,src,msg){
			$('.item').show();
			$('.hint-pic img').attr('class', attr);
			$('.hint-pic img').attr('src',src);
			$('.hint-erro').text(msg)
		}

        // 我知道了
        $('.hint-btn').click(function () {
            $('.item').hide();
        })

    })
</script>

</html>
